<template>
  <div class="box-footer">
    <!-- 勾选 -->
    <div class="form-check">
      <input
        class="form-check-input"
        type="checkbox"
        value=""
        id="flexCheckDefault"
        :checked="props.full"
        @change="onFullChange"
      />
      <label class="form-check-label" for="flexCheckDefault">{{ fullText }}</label>
    </div>

    <!-- 总价 -->
    <div>
      总价：<span class="price">￥{{ amount }}</span>
    </div>

    <!-- 购买数量 -->
    <button class="btn btn-primary" type="submit">结算({{ props.total }})</button>
  </div>
</template>

<script setup>
// 依赖
import { defineProps, computed, defineEmits } from 'vue'

// 自定义属性
const props = defineProps({
  amount: {
    type: Number,
    default: 0
  },
  total: {
    type: Number,
    default: 0
  },
  full: {
    type: Boolean,
    required: true
  }
})

// 自定义事件
const emit = defineEmits(['full-change'])

// 总价格
const amount = computed(() => props.amount.toFixed(2))
// 全选、反选的文本
const fullText = computed(() => (props.full ? '反选' : '全选'))

// 全选状态发生变化
const onFullChange = e => emit('full-change', e.target.checked)
</script>

<style lang="less" scoped>
.form-check-input[type='checkbox'] {
  border-radius: 10px;
  margin-top: 2px;
}
.box-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  padding: 0 10px 0 10px;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 45px;
  border-top: 1px solid #efefef;
  font-size: 12px;
  background-color: #fff;

  .form-check {
    position: relative;
    top: 3px;
  }

  .price {
    color: red;
    font-weight: bold;
  }

  .btn-primary {
    font-size: 12px;
    text-align: center;
    border-radius: 30px;
    min-width: 80px;
  }
}
</style>
